<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%
    String rootPath = request.getContextPath();
%>
<!DOCTYPE>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>我的收货地址</title>
<meta name="viewport" content="initial-scale=1, maximum-scale=1" />
<meta name="apple-mobile-web-app-capable" content="yes" />
<meta name="apple-mobile-web-app-status-bar-style" content="black" />
<link rel="stylesheet"
	href="//g.alicdn.com/msui/sm/0.6.2/css/sm.min.css" />
<link rel="stylesheet"
	href="//g.alicdn.com/msui/sm/0.6.2/css/sm-extend.min.css" />
<!-- 	<link href="http://cdn.static.runoob.com/libs/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"> -->
<link rel="stylesheet" href="../static/weixin.css" />
</head>
<body>
	<div class="content">
		<c:forEach items="${addresses}" var="address">
			<div class="card">
				<div class="card-header">收货人:${address.username}&nbsp;&nbsp;&nbsp;${address.phone}</div>
				<div class="card-content">
					<div class="card-content-inner">收货地址:${address.area}&nbsp;${address.street}&nbsp;${address.address}</div>
				</div>
				<div class="card-footer">
					<div class="item-input">
						<input type="checkbox" name="isdefault"
							value="${address.addressid}" onClick="doDefault(this);"
							<c:if test="${address.isdefault==1}">checked</c:if> /> 设为默认 <label
							class="label-switch"> <!-- <input type="checkbox" >
	                		<div class="checkbox">${address.username}</div> -->
						</label>
					</div>
					<div class="item-input" onClick="doEditAddr(${address.addressid});">
						<span class="icon icon-home"></span>编辑
					</div>
					<div class="item-input"
						onClick="doDelete(${address.addressid},this);">
						<span class="icon icon-remove"></span>删除
					</div>
				</div>
			</div>
		</c:forEach>
	</div>

	<nav class="bar bar-tab" onclick="doAddAddr();">
		<a href="#" class="button button-big button-fill button-danger"> <span
			class="icon icon-edit"></span>新建地址
		</a>
	</nav>

	<script type='text/javascript'
		src='<%=rootPath%>/static/js/jquery-3.1.1.min.js' charset='utf-8'></script>

	<script type='text/javascript'
		src='//g.alicdn.com/sj/lib/zepto/zepto.min.js' charset='utf-8'></script>
	<script type='text/javascript'
		src='//g.alicdn.com/msui/sm/0.6.2/js/sm.min.js' charset='utf-8'></script>
	<script type='text/javascript'
		src='//g.alicdn.com/msui/sm/0.6.2/js/sm-extend.min.js' charset='utf-8'></script>

	<script type="text/javascript">
		function doAddAddr() {
			self.location = '<%=rootPath%>/weixin/memberaddaddr';
		}
		
		function doEditAddr(addressId) {
			self.location = '<%=rootPath%>/weixin/membereditaddr?addressId='+addressId;
		}
		
		function doDefault(ck)
		{
			
			if(ck.checked){
				/* $("input[name='isdefault']").each(function(){this.checked=true;});  */
			var ajaxurl="<%=rootPath%>/weixin/addrdefault";
				/* var	htmlobj=$.ajax({url:ajaxurl,async:false});
				alert(htmlobj.responseText); */
		         $.ajax({
		             type: "POST",
		             url: ajaxurl,//点击登录按钮走的action
		            /*  data: {username:$("#username").val(), password:$("#password").val()}, */
		             data:{addressId:ck.value},
		             dataType: "json",
		             success: function(data){
		            	 //alert("success");
		            	 //console.info(data.flag);
		            	 if(data.flag == true){
		            		/*  window.location = 'login/login';//用户名&密码正确时跳转至blog页面 */
		            		alert(data.msg);
		            		/* $("input[type=checkbox]").each(function(){ //由于复选框一般选中的是多个,所以可以循环输出 
		        				if($(this).val()!=ck.value); {
		        					$(this).prop("checked", false); 
		        				}
		        			});  */
		            		$("input[type=checkbox]").prop("checked", false);
		        			ck.checked=true;
		            	 } 
		             },
		             error: function(data){
		            	 alert("error");
		            	 console.info(data.msg);
		            	/*  alert(data.msg); */
		             }
		         });	 
			}
		}
		
		
		function doDelete(addressId,div)
		{
			var ajaxurl="<%=rootPath%>/weixin/deleteaddr?addressId="+addressId;
			var	htmlobj=$.ajax({url:ajaxurl,async:false});
			$(div).parent().parent(".card").remove();
			alert(htmlobj.responseText);
			$.toast(htmlobj.responseText);
			
		}

	</script>

</body>
</html>